#!/usr/bin/env node

const Koa = require('koa'),
      log = console.log;

const app = new Koa();
//用use加载中间件，固定参数，ctx上下文,next确保后面的中间件调用

// M-logger
app.use((ctx,next)=>{
  //解析请求
  log(`${ctx.method} ${ctx.path}`);
  next();
  //组装响应
});
app.use((ctx,next)=>{  //M-ms
  const start = Date.now()
  next();
  const end  = Date.now();
  log(`cost :${end-start}ms`);

})
app.use((ctx,next)=>{   //M-hello
  //解析请求
  //封装响应
  ctx.body = 'hello koa';

});

app.listen(8080);
